﻿using Dapper;
using Microsoft.Data.SqlClient;
using WebApplication1.Entity;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace WebApplication1.Server
{
    public class UserServer
    {
        public List<UserEntity> GetList()
        {
            try
            {
                //Server=LAPTOP-RDM63KV8;Database=ORMText;User ID=sa;Password=123456;TrustServerCertificate=True;\r\n

                var connectionString = "Server=127.0.0.1;Database=ORMText;User Id=sa;Password=123456;Encrypt=True;TrustServerCertificate=Yes;\r\n\r\n";

                var connection = new SqlConnection(connectionString);
                connection.Open();

                var users = connection.Query<UserEntity>(
                    "SELECT * FROM [User]" // 避免 SQL 关键字冲突，建议加方括号
                ).AsList();

                return users;
            }
            catch (Exception ex)
            {
                // 记录日志或处理异常
                throw new Exception("获取用户列表失败", ex);
            }
        }
    }
}
